﻿using System;
using System.ComponentModel.Composition;
using System.Threading.Tasks;
using DeepZoomPivotConstructor.VisualLib;
using RenderEngineInterfaces;

namespace StringUriRender
{
    [Export(typeof(IRenderItem))]
    [RenderInfo(typeof(string))]
    public class RenderStringToUri : IRenderItem
    {
        [Import]
        private IRenderEngine MyRender { get; set; }

        public Task<Visual> Render(object what)
        {
            Uri u = new Uri(what as string);
            return MyRender.RenderToFuture(u);
        }

        /// <summary>
        /// If this is http, then go!
        /// </summary>
        /// <param name="what"></param>
        /// <returns></returns>
        public RenderPluginPriority RenderPriority(object what)
        {
            string url = what as string;
            if (!url.StartsWith("http://") && !url.StartsWith("https://"))
            {
                return RenderPluginPriority.RPPCantDoIt;
            }
            try
            {
                Uri u = new Uri(url);
                return RenderPluginPriority.RPPGeneric;
            }
            catch
            {
            }

            return RenderPluginPriority.RPPCantDoIt;
        }
    }
}
